package com.bear.demo1;

import static java.lang.Thread.sleep;

/** 守护线程
 * @author LiuShanshan
 * @version V1.0
 * @Description
 */
public class DaemonDemo {
    public static void main(String[] args) throws InterruptedException {
        demo1();
    }
    public static void demo1() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            System.out.println("开始运行...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("fsfa运行结束...");
        }, "daemon");
        // 设置该线程为守护线程
        t1.setDaemon(true);
        t1.start();
        Thread.sleep(1);
        System.out.println("运行结束...");
    }
}
